-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subscription oauth v2 #1033
base: main
Are you sure you want to change the base?
Subscription oauth v2 #1033
Conversation
# Conflicts: # Sources/Networking/README.md # Sources/Networking/v2/APIRequestErrorV2.swift # Sources/Networking/v2/APIRequestV2.swift # Sources/Networking/v2/APIResponseConstraints.swift # Sources/Networking/v2/APIService.swift # Sources/TestUtils/MockAPIService.swift # Tests/NetworkingTests/v2/APIServiceTests.swift
# Conflicts: # Package.swift
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Second part of the review
public final class SessionDelegate: NSObject, URLSessionTaskDelegate { | ||
|
||
/// Disable automatic redirection, in our specific OAuth implementation we manage the redirection, not the user | ||
public func urlSession(_ session: URLSession, task: URLSessionTask, willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest) async -> URLRequest? { | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like it is used only in one test. Please confirm if this is relevant and move accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean the entire SessionDelegate
? no, it's used in the OAuthClient init in the main apps
let urlSession = URLSession(configuration: configuration,
delegate: SessionDelegate(),
delegateQueue: nil)
} | ||
|
||
/// The sole entity responsible of obtaining, storing and refreshing an OAuth Token | ||
public protocol SubscriptionTokenProvider { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a big file I would split out these additional protocols and enums not directly related to SubscriptionManager to separate files for improved readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved SubscriptionFeature and SubscriptionTokenProvider to dedicated files
public func isFeatureActive(_ entitlement: SubscriptionEntitlement) async -> Bool { | ||
guard isUserAuthenticated else { return false } | ||
|
||
let currentFeatures = await currentSubscriptionFeatures(forceRefresh: false) | ||
return currentFeatures.contains { feature in | ||
feature.entitlement == entitlement && feature.enabled | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this naming confusing. Let's go one by one, currentSubscriptionFeatures
above is clear and well defined, features that are provided by current subscription. But when you move to isFeatureActive
and SubscriptionFeature.enabled
it can be interpreted in multiple ways (e.g. isFeatureActive(.networkProtection)
, does it mean that VPN is running? etc.).
isFeatureActive
- means if the feature is provided within the current subscription and if current user has entitlements to use it, previously we sticked to established vocabulary and checked if used has entitlements to a feature. If you don't like this maybe something along the lineisFeatureAvailableForUser
?SubscriptionFeature.enabled
- this is the underlying property storing Bool for the above so I would align them together
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree:
isFeatureActive
renamedisFeatureAvailableForUser
SubscriptionFeature.enabled
renamedavailableForUser
cacheSerialQueue.sync { | ||
subscriptionCache.reset() | ||
} | ||
// NotificationCenter.default.post(name: .subscriptionDidChange, object: self, userInfo: nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please double check if this is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed for now, anything related to the subscription cancellation is handled by the signOut that sends the proper notification. I'm keeping this commented to remind me where it COULD be if I need it, not to be merged anyway.
# Conflicts: # Sources/PrivacyDashboard/PrivacyDashboardUserScript.swift
…i/subscription_oauth_api_v2 # Conflicts: # Sources/Common/Extensions/DateExtension.swift # Sources/MaliciousSiteProtection/API/APIClient.swift # Sources/Networking/v2/APIRequestV2.swift # Sources/NetworkingTestingUtils/MockLegacyTokenStorage.swift # Sources/NetworkingTestingUtils/MockOAuthClient.swift # Sources/NetworkingTestingUtils/MockTokenStorage.swift # Tests/NetworkingTests/v2/APIRequestV2Tests.swift # Tests/NetworkingTests/v2/APIServiceTests.swift # Tests/NetworkingTests/v2/Extensions/DictionaryURLQueryItemsTests.swift
Task/Issue URL: https://app.asana.com/0/1205842942115003/1207991044706235/f
iOS PR: duckduckgo/iOS#3480
macOS PR: duckduckgo/macos-browser#3580
What kind of version bump will this require?: Major
CC: @miasma13
iOS PR: duckduckgo/iOS#3480
macOS PR: duckduckgo/macos-browser#3580
Description:
This PR introduces the use of OAuth V2 authentication in Privacy Pro Subscription.
The code changes are comprehensive due to the paradigm changes between the old access token lifecycle and the new JWT lifecycle.
The Subscription UI and UX should be unchanged.
Steps to test this PR:
Test all Privacy Pro Subscription features and UX, more details here
Internal references:
Software Engineering Expectations
Technical Design Template